package com.jerry.template.module.mainpage.find;

import android.support.annotation.NonNull;

import com.google.gson.Gson;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.jerry.template.R;
import com.jerry.template.base.BaseActivity;
import com.jerry.template.constant.Urls;
import com.jerry.template.module.mainpage.find.adapter.BannerListAdapter;
import com.jerry.template.module.mainpage.find.entity.BannerList;
import com.jerry.template.utils.EventMessage;
import com.jerry.template.utils.OkHttpUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by chenhuan on 2016/5/13.
 */
public class BannerListActivity extends BaseActivity{

    @BindView(R.id.dapeiriji_list_pulllistview)
    PullToRefreshListView listView;

    private List<BannerList.DataBean1.DataBean> dataBeans = new ArrayList<>();
    private BannerListAdapter adapter;

    @Override
    protected int getLayoutId(){
        return R.layout.activity_banner_list;
    }


    @OnClick(R.id.back_to_find)
    public void goBack(){
        finish();
    }

    @Override
    protected void loadData(){
        //OkHttpUtils.get(Urls.DAPEIRIJI_LIST,new HashMap<String, Object>());
        OkHttpUtils.postSubmitForm(Urls.DAPEIRIJI_LIST,null);
    }

    @Override
    protected void initViews(){

        /*setInterfaceNotify(new IntenrFaceCompare(){
            @Override
            public void startNotifyData(BannerList.DataBean1.DataBean dataBean){
                dataBean1s.add(dataBean);
                adapter = new BannerListAdapter(BannerListActivity.this,dataBean1s);
                listView.setAdapter(adapter);
            }
        });*/




    }

    @Override
    protected void postEventResult(@NonNull EventMessage message){
        if(message!=null){
            if(Urls.DAPEIRIJI_LIST.equals(message.type)){
                Gson gson = new Gson();
                BannerList bannerList = gson.fromJson(message.result, BannerList.class);

                dataBeans.addAll(bannerList.getData().getData());
                adapter = new BannerListAdapter(this,dataBeans);

                listView.setAdapter(adapter);

               /* BannerList.DataBean1.DataBean dataBean = new BannerList.DataBean1.DataBean();
                dataBean1s.addAll(bannerList.getData().getData());
                listener.startNotifyData(dataBean);*/
            }
        }
    }

    //接口回调
   /* private IntenrFaceCompare listener;
    public void setInterfaceNotify(IntenrFaceCompare listener){
        this.listener = listener;
    }*/
}
